#include "widget.h"
#include "ui_widget.h"
#include <QMediaPlayer>
#include <QSlider>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    player = new QMediaPlayer(this);
    videowidget = new QVideoWidget(this);
    videowidget->setMinimumSize(800,800);
    this->vbox = new QVBoxLayout(this);
    this->setLayout(this->vbox);
    choosebtn = new QPushButton("选择视频",this);
    playbtn = new QPushButton(this);
    playbtn->setIcon(this->style()->standardIcon(QStyle::SP_MediaPlay));
    QHBoxLayout* hbox = new QHBoxLayout;
    hbox->addWidget(choosebtn);
    hbox->addWidget(playbtn);
    vbox->addWidget(videowidget);
    vbox->addLayout(hbox);
    connect(choosebtn,&QPushButton::clicked,this,&Widget::chooseVideo);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::chooseVideo()
{
    QString name = QFileDialog::getOpenFileName(this, "选择视频", ".", "MP4 Files (*.mp4)");
    if (!name.isEmpty()) {
        player->setMedia(QUrl::fromLocalFile(name));
        player->setVideoOutput(videowidget);
    }
}

